<template>
  <!-- 排行榜 -->
  <div class="ranking">
    <div class="pb2">
      <MyHead title="高校签到排行榜" style="background: #f8f8f8"></MyHead>
      <div class="events-box">
        <div class="serach-box">
          <div class="serach-btn flexe" @click="showFilters">
            <van-icon name="search" /> 搜索
          </div>
        </div>
        <div class="school-ranking">高校排行榜</div>
        <div class="school-even">{{ rankingInfo.act_title }}</div>
      </div>
      <div class="content-box">
        <div class="content-list">
          <div class="item2 flexc font-style">排名</div>
          <div class="item6 school-name font-style">学校名称</div>
          <div v-if="type == 1" class="item2 flexc font-style">签到人数</div>
          <div v-if="type == 2" class="item2 flexc font-style">签到率</div>
        </div>
        <div
          class="content-list"  v-for="(item, index) in rankingInfo.act_data" :key="index" >
          <div class="item2 flexc">{{ item.rank }}</div>
          <div class="item6">
            <van-icon name="award" color="red" />{{ item.name }}
          </div>
          <div v-if="type == 1" class="item2 flexc">{{ item.act_num }}</div>
          <div v-if="type == 2" class="item2 flexc">{{ item.rate }}</div>
        </div>
        <div v-if="this.rankingInfo.act_data == 0">
          <van-empty description="暂无排行榜" />
        </div>
      </div>
      <!-- 搜索 -->
      <van-popup
        v-model="show"
        position="right"
        :style="{ width: '70%', height: '100vh' }"
        closeable
        close-icon-position="top-right"
      >
        <div class="popbox">
          <div class="title">筛选条件</div>
          <div class="form">
            <van-cell-group v-model="screenForm">
              <myPicker
                :form="screenForm"
                v-model="screenForm.act_id_label"
                value-key="title"
                name="act_id"
                :columns="eventsType"
                label="选择活动"
                placeholder="请选择"
                :norequired="true"
              ></myPicker>
              <myPicker
                :form="screenForm"
                v-model="screenForm.type_label"
                value-key="type_name"
                name="type"
                :columns="sortType"
                label="排序方式"
                placeholder="请选择"
                :norequired="true"
              ></myPicker>
              <myPicker
                :form="screenForm"
                v-model="screenForm.depart_code_label"
                value-key="name"
                name="depart_code"
                :columns="eventsDistrict"
                label="选择地区"
                placeholder="请选择"
                :norequired="true"
              ></myPicker>
            </van-cell-group>
          </div>
          <div class="btn-style">
            <van-button
              color="#999999"
              round
              type="info"
              @click="screenCancel"
              style="margin-left: 20px"
              >取消</van-button
            >
            <van-button
              color="#E21B1B"
              round
              type="info"
              @click="screenSubmit"
              style="margin-left: 20px"
              >提交</van-button
            >
          </div>
        </div>
      </van-popup>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      openid: $.cookie("openid"),
      rankingInfo: {},
      show: false,
      screenForm: {},
      eventsType: [],
      sortType: [], //排序方式
      eventsDistrict: [], //地区
      type: "", // 1:签到人数，2：签到率
    };
  },
  components: {},
  methods: {
    /*排行榜信息*/
    async getRank() {
      let res = await this.$ajax.actrank({
        openid: this.openid,
      });
      if (res.code == 1) {
        this.rankingInfo = res.data;
        this.type = res.data.type; //类型:1-签到人数，2签到率
      } else {
        this.$toast(res.msg);
      }
    },

    showFilters() {
      this.show = true;
    },
    /*关闭*/
    onFilterClose() {
      this.show = false;
    },

    /*筛选下拉数据（等接口）*/
    async getSerchInfoList() {
      let res = await this.$ajax.rankconditions({
        openid: this.openid,
      });
      if (res.code == 1) {
        this.eventsType = res.data.activitys;
        this.sortType = res.data.ranktype;
        this.eventsDistrict = res.data.departlist;
      }
    },

    /*取消*/
    screenCancel() {
      this.screenForm = {};
      this.getRank(); //默认列表数据
      this.show = false;
    },
    /*搜索提交*/
    async screenSubmit() {
      let res = await this.$ajax.actrank({
        openid: this.openid,
        depart_code: this.screenForm.depart_code,
        act_id: this.screenForm.act_id,
        type: this.screenForm.type,
      });
      if (res.code == 1) {
        this.rankingInfo = res.data;
        this.type = res.data.type;
        this.screenForm = {};
        this.show = false;
      } else {
        this.$toast(res.msg);
      }
    },
  },
  mounted() {
    this.getRank(); //高校排行榜列表
    this.getSerchInfoList(); //筛选下拉数据
  },
};
</script>

<style lang="scss" scoped>
.font-style {
  font-weight: bold;
}

.ranking {
  width: 100%;
  min-height: 100vh;
  background: linear-gradient(to bottom right, #f44336 50%, #b71c1c);
  .events-box {
    width: 100%;
    color: white;
    font-size: 28px;
    font-family: SourceHanSansSC-regular;
    line-height: 45px;
    padding: 20px 0px;
    position: relative;
    background-image: url(../../assets/images/gxphb-bg.png);
    background-position: right bottom;
    background-repeat: no-repeat;
    background-size: 180px 120px;

    .serach-box {
      width: 100%;
      height: 30px;
      line-height: 20px;
      display: flex;
      display: grid;
      justify-content: right;
      margin-top: 12px;
      .serach-btn {
        width: 60px;
        height: 30px;
        border-top-left-radius: 8px;
        border-bottom-left-radius: 8px;
        background-color: #f6b730;
        font-size: 14px;
        align-items: center;
      }
    }
    .school-ranking {
      font-weight: bold;
      padding: 0px 20px;
    }
    .school-even {
      font-size: 20px;
      padding: 0px 20px;
    }
    .img-box {
      width: 150px;
      height: 100px;
      overflow: hidden; /* 隐藏超出容器的部分 */
      position: absolute;
      top: 82px;
      right: 20px;
      .img {
        width: 100%;
        height: 100%;
        background-repeat: no-repeat;
        background-size: auto 100%;
      }
    }
  }
  .content-box {
    line-height: 20px;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 1);
    margin: 10px 25px;
    margin-bottom: 0px;
    box-sizing: border-box;
    padding: 10px;
    line-height: 30px;
    .content-list {
      display: flex;
      justify-content: space-around;

      .item2 {
        width: 20%;
      }
      .item6 {
        width: 60%;
      }
      .school-name {
        display: flex;
        justify-content: space-around;
      }
    }
  }
}
// 筛选条件
.popbox {
  height: 100vh;
  width: 100%;
  padding: 0px;
  .title {
    color: rgba(16, 16, 16, 1);
    font-size: 16px;
    text-align: left;
    font-family: SourceHanSansSC-bold;
    font-weight: bold;
    margin-top: 10px;
    padding-left: 20px;
  }
  .form {
    margin-top: 15px;
  }
  .btn-style {
    display: flex;
    position: absolute;
    bottom: 20px;
    .van-button {
      width: 100px;
    }
  }
}
</style>